package xj.toolkit.redis.single;

import java.util.List;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo;
import xj.toolkit.redis.Jedis2Commands;
import xj.toolkit.redis.Pipelinable;
import xj.toolkit.redis.PipelineExecutor;
import xj.toolkit.redis.TransactionExector;
import xj.toolkit.redis.TransactionSupport;

public class Jedis2 extends Jedis implements Jedis2Commands {

	protected Jedis2Pool dataSource = null;

	public Jedis2(String host) {
		super(host);
	}

	public Jedis2(String host, int port) {
		super(host, port);
	}

	public Jedis2(String host, int port, int timeout) {
		super(host, port, timeout);
	}

	public Jedis2(JedisShardInfo shardInfo) {
		super(shardInfo);
	}

	public void setDataSource(Jedis2Pool pool) {
		this.dataSource = pool;
	}

	@Override
	public void close() {
		if (dataSource != null) {
			Jedis2Pool pool = dataSource;
			this.dataSource = null;
			if (client.isBroken()) {
				pool.returnBrokenResource(this);
			} else {
				pool.returnResource(this);
			}
		} else {
			super.close();
		}
	}

	/**
	 * @see xj.toolkit.redis.Pipelinable#sync(xj.toolkit.redis.PipelineExecutor)
	 */
	public void sync(PipelineExecutor executor) {

	}

	/**
	 * @see xj.toolkit.redis.Pipelinable#syncAndReturnAll(xj.toolkit.redis.PipelineExecutor)
	 */
	public List<Object> syncAndReturnAll(PipelineExecutor executor) {
		return null;
	}

	/**
	 * @see xj.toolkit.redis.TransactionSupport#exec(xj.toolkit.redis.TransactionExector)
	 */
	public List<Object> exec(TransactionExector exector) {
		return null;
	}

	/**
	 * @see xj.toolkit.redis.Jedis2Commands#lpushx(java.lang.String,
	 *      java.lang.String)
	 */
	public Long lpushx(String s, String s1) {
		return null;
	}
}
